<template>
    <!-- 详情 -->
    <el-dialog title="确认授信额度" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="auto">
            <el-form-item label="授信额度" prop="amount">
                <c-number-input v-model="ruleForm.amount" placeholder="请输入授信额度">
                    <template slot="append">万元</template>
                </c-number-input>
            </el-form-item>
        </el-form>
        <span slot="footer">
            <el-button :loading="loading" @click="handleClose">取 消</el-button>
            <el-button :loading="loading" type="primary" @click="handleSubmit">确 定</el-button>
        </span>
    </el-dialog>
</template>
<script>
export default {
    data () {
        return {
            dialogVisible: false,
            ruleForm: {},
            loading: false,
            rules: {
                amount: [
                    { required: true, message: "请输入授信额度", trigger: "change" },
                ],
            },
        };
    },
    methods: {
        handleSubmit () {
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    this.loading = true;
                    this.$post({
                        url: "/DealerCreditAmountApply/platformConfirm",
                        data: this.ruleForm,
                    }).then(
                        () => {
                            this.$message.success("操作成功");
                            this.loading = false;
                            this.handleClose();
                            this.$parent.tableList();
                        },
                        () => {
                            this.loading = false;
                        }
                    );
                }
            });
        },
        handleOpen (item) {
            this.loading = false;
            if (item) {
                this.ruleForm = {
                    id: item.id,
                    amount: item.bankAmount / 10000
                };
            }
            this.dialogVisible = true;
        },
        handleClose () {
            this.ruleForm = {};
            this.$refs.ruleForm.resetFields();
            this.dialogVisible = false;
        },
    },
};
</script>
